package lc.q51_100;

import java.util.ArrayList;
import java.util.List;

public class Q90 {

    public List<List<Integer>> subsetsWithDup(int[] nums) {
        List<List<Integer>> result = new ArrayList<>();
        // 存入一个空的值
        result.add(new ArrayList<>());
        // -10 到 10
        int[] allNums = new int[21];
        for (int num : nums) {
            allNums[num + 10] ++;
        }
        for (int i = -10; i <= 10 ; i++) {
            int times = allNums[i + 10];
            if (times == 0) {
                continue;
            }
            int size = result.size();
            for (int k = 0;k < size;k ++ ) {
                List<Integer> integers = result.get(k);
                for (int j = 1; j <= times; j++) {
                    List<Integer> es = new ArrayList<>(integers);
                    for (int l = 0; l < j; l++) {
                        es.add(i);
                    }
                    result.add(es);
                }
            }

        }
        return result;
    }

    public static void main(String[] args) {
        Q90 q90 = new Q90();
        System.out.println(q90.subsetsWithDup(new int[]{1,2,2}));
    }
}
